package com.wxy.web.mapper;

import com.wxy.web.model.Permission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author wxy
 * @since 2021-06-14
 */
public interface PermissionMapper extends BaseMapper<Permission> {

    @Select("select permission.id from permission left join role_permission on permission.id = role_permission.permission_id where role_permission.role_id='${roleId}'")
    public ArrayList<Integer> listPermissionIdsByRoleId(@Param("roleId") Integer roleId);

    @Select("select permission.id from permission left join role_permission on permission.id = role_permission.permission_id where role_permission.role_id='${roleId}'")
    public ArrayList<Integer> listPermissionCodesByRoleId(@Param("roleId") Integer roleId);

    @Select("select permission.id from permission left join role_permission on permission.id = role_permission.permission_id left join user_role on role_permission.role_id = user_role.role_id where user_role.user_id='${userId}'")
    public ArrayList<Integer> listPermissionCodesByUserId(@Param("userId") Integer userId);
}
